package cst.a331cs.recyclertest331cs.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cst.a331cs.recyclertest331cs.adapter.MyAdapter;
import cst.a331cs.recyclertest331cs.R;
import cst.a331cs.recyclertest331cs.bean.ArticleBean;
import cst.a331cs.recyclertest331cs.iface.ArticleListener;
import cst.a331cs.recyclertest331cs.model.ArticleModel;

public class MainActivity extends AppCompatActivity implements ArticleListener{
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    List<ArticleBean> list;
    private void initRecyclerView(){
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
       // list = getData();
        myAdapter = new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);

    }
    /*private List<ArticleBean> getData() {
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean art;

        art = new ArticleBean();
        art.setId(1);
        art.setName("标题1");
        art.setThumb(R.drawable.f1);
        art.setUpdate_time("2017-5-1 15:16");
        art.setDescription("描述1");
        list.add(art);

        art = new ArticleBean();
        art.setId(2);
        art.setName("标题2");
        art.setThumb(R.drawable.f2);
        art.setUpdate_time("2017-5-2 15:16");
        art.setDescription("描述2");
        list.add(art);

        art = new ArticleBean();
        art.setId(3);
        art.setName("标题3");
        art.setThumb(R.drawable.f3);
        art.setUpdate_time("2017-5-3 15:16");
        art.setDescription("描述3");
        list.add(art);

        art = new ArticleBean();
        art.setId(4);
        art.setName("标题4");
        art.setThumb(R.drawable.f4);
        art.setUpdate_time("2017-5-4 15:16");
        art.setDescription("描述4");
        list.add(art);

        art = new ArticleBean();
        art.setId(5);
        art.setName("标题5");
        art.setThumb(R.drawable.f5);
        art.setUpdate_time("2017-5-5 15:16");
        art.setDescription("描述5");
        list.add(art);

        art = new ArticleBean();
        art.setId(6);
        art.setName("标题6");
        art.setThumb(R.drawable.f6);
        art.setUpdate_time("2017-5-6 15:16");
        art.setDescription("描述6");
        list.add(art);

        return list;
    }*/


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",this);
    }

    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list = list;
        myAdapter.setList(list);

    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this,"fail:"+msg,Toast.LENGTH_SHORT).show();
    }
}
